package com.neu.ui.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.neu.annoation.NeedLogin;

public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		// 请求结束后做的事情
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		// 回去的时候做的事
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object target) throws Exception {
		// TODO Auto-generated method stub
		// 进来前做的事情
		
		System.out.println("进入拦截器");
		/*HandlerMethod hMethod = (HandlerMethod) target;
		NeedLogin needLogin = hMethod.getMethodAnnotation(NeedLogin.class);
		if (needLogin == null) {// 不存在需要过滤的拦截器注解，直接放行
			return true;
		}*/
//
//		if (request.getSession().getAttribute("cur_user")!=null) {
//			return true;}
//		response.sendRedirect(request.getContextPath()+"/user/login");
//		return false;
		return true;
	}

}
